home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1996 #6 / Amiga Plus CD - 1996 - No. 06.iso / pd / programmierung / proasm / routines / commodity.r < prev    next >
Text File  |  1994-04-15  |  7KB  |  279 lines

  1.  
  2. ;---;  commodity.r  ;----------------------------------------------------------
  3. *
  4. *    ****    Commodities Support Routines    ****
  5. *
  6. *    Author        Daniel Weber
  7. *    Version        1.10
  8. *    Last Revision    28.05.93
  9. *    Identifier    csr_defined
  10. *       Prefix        csr_    (commodities support routines)
  11. *                 ¯         ¯       ¯
  12. *    Functions    InitBroker, RemoveBroker, InstallHotKey, RemCX
  13. *            EnabeCX, DisableCX
  14. *
  15. *    Note        - The commodity.library (v37) must already be open
  16. *              and available using the CxBase(pc) effective address.
  17. *            - Some descriptions taken from the AmigaMails (easier
  18. *              and more precise).
  19. *
  20. ;------------------------------------------------------------------------------
  21.  
  22. ;------------------
  23.     ifnd    csr_defined
  24. csr_defined    SET    1
  25.  
  26. ;------------------
  27. csr_oldbase    equ __BASE
  28.     base    csr_base
  29. csr_base:
  30.  
  31. ;------------------
  32.     opt    sto,o+,ow-,q+,qw-        ;all optimisations on
  33.  
  34. ;------------------
  35.  
  36.     incdir    'include:','routines:'
  37.     include    ports.r
  38.     include    structs.r
  39.     include libraries/commodities.i
  40. ;    incequ    lvo.s
  41.  
  42. ;------------------------------------------------------------------------------
  43.  
  44.     IFND    EVT_HOTKEY
  45. EVT_HOTKEY    EQU    1    ;like in the AmigaMails (keep the compatibility)
  46.     ENDC
  47.  
  48. ;------------------------------------------------------------------------------
  49. *
  50. * InitBroker    - Initialize and start broker (port will be created)
  51. *
  52. * INPUT        A0    Message Port Structure (use PortStruct_ from Structs.r)
  53. *        A1    New Broker Structure (BrokerStruct_ from Structs.r)
  54. *
  55. * RESULT    D0    Broker (co)
  56. *        D1    Broker Message Port
  57. *
  58. ;------------------------------------------------------------------------------
  59.     IFD    xxx_InitBroker
  60.  
  61. InitBroker:
  62.     movem.l    d2-a6,-(a7)
  63.     bsr    MakePort
  64.     beq.s    \error
  65.     move.l    d0,d6
  66.     move.l    d0,nb_Port(a1)
  67.  
  68. ; The commodities.library function CxBroker() adds a broker to the master list.
  69. ; It takes two arguments, a pointer to a NewBroker structure and a pointer to
  70. ; a LONG.  The NewBroker structure contains information to set up the broker.
  71. ; If the second argument is not NULL, CxBroker will fill it in with an error
  72. ; code.
  73.  
  74.     move.l    a1,a0            ;broker
  75.     moveq    #0,d0            ;NULL
  76.     move.l    CxBase(pc),a6
  77.     jsr    -36(a6)            ;_LVOCxBroker(a6)
  78.     move.l    d0,d7
  79.     beq    \error2
  80.  
  81.     move.l    d6,d1            ;message port
  82.     move.l    d7,d0            ;broker (co)
  83. \out:    movem.l    (a7)+,d2-a6
  84.     rts
  85.  
  86. ;------------------
  87. \error2:                ;no broker
  88.     move.l    d6,a0
  89.     move.l    a0,d6
  90.     beq.s    \error
  91.     bsr    UnMakePort
  92. \error:    moveq    #0,d0            ;no port
  93.     moveq    #0,d1
  94.     bra.s    \out
  95.  
  96.     ENDC
  97.  
  98. ;------------------------------------------------------------------------------
  99. *
  100. * RemoveBroker    - Remove broker from system and close/remove port
  101. *
  102. * INPUT        D0    Flag (0: remove all,  -: remove only broker)
  103. *        A0    Broker (co)
  104. *        A1    Message Port
  105. *
  106. ;------------------------------------------------------------------------------
  107.     IFD    xxx_RemoveBroker
  108.  
  109. RemoveBroker:
  110.     movem.l    d0-a6,-(a7)
  111.  
  112. ; It's time to clean up.  Start by removing the broker from the Commodities
  113. ; master list.  The DeleteCxObjAll() function will take care of removing a
  114. ; CxObject and all those connected to it from the Commodities network.
  115.  
  116.     move.l    a1,a4                ;just store it
  117.     move.l    CxBase(pc),a6
  118.     tst.l    d0
  119.     beq.s    \all
  120.     jsr    -48(a6)            ;_LVODeleteCxObj(a6)
  121.     bra.s    \port
  122.  
  123. \all:    jsr    -54(a6)            ;_LVODeleteCxObjAll(a6)
  124. \port:    move.l    a4,a0
  125.     bsr    UnMakePort
  126.     movem.l    (a7)+,d0-a6
  127.     rts
  128.  
  129.     ENDC
  130.  
  131. ;------------------------------------------------------------------------------
  132. *
  133. * InstallHotKey    - install a HotKey (HotKey triad)
  134. *
  135. * INPUT        D0    ID (user specified)
  136. *        A0    HotKey String
  137. *        A1    Broker
  138. *        A2    Broker Message Port
  139. *
  140. * RESULT    D0    Filter object or zero if failed
  141. *
  142. ;------------------------------------------------------------------------------
  143.     IFD    xxx_InstallHotKey
  144.  
  145. InstallHotKey:
  146.     movem.l    d1-a6,-(a7)
  147.     move.l    d0,d6            ;store ID
  148.     move.l    a1,a4            ;store broker
  149.  
  150. ; This filter passes input events that match the string pointed to by hotkey.
  151.  
  152.     move.l    CxBase(pc),a6
  153.     move.l    #CX_FILTER,d0
  154.     sub.l    a1,a1
  155.     jsr    -30(a6)            ;_LVOCreateCxObj(a6)    ;CxFilter
  156.     move.l    d0,d7
  157.     beq    \error
  158.     move.l    a4,a0            ;broker
  159.     move.l    d0,a1            ;filter
  160.     jsr    -84(a6)            ;_LVOAttachCxObj(a6)
  161.  
  162. ; CxSender() creates a sender CxObject.  Every time a sender gets a CxMessage,
  163. ; it sends a new CxMessage to the port pointed to in the first argument.
  164. ; CxSender()'s second argument will be the ID of any CxMessages the sender
  165. ; sends to the port.  The data pointer associated with the CxMessage will
  166. ; point to a *COPY* of the InputEvent structure associated with the orginal
  167. ; CxMessage.
  168.  
  169.     move.l    #CX_SEND,d0
  170.     move.l    a2,a0            ;broker_mp (port)
  171.     move.l    d6,a1            ;ID
  172.     jsr    -30(a6)            ;_LVOCreateCxObj(a6)    ;CxSender
  173.     move.l    d0,d6
  174.     beq    \error
  175.     move.l    d7,a0            ;filter
  176.     move.l    d0,a1            ;sender object
  177.     jsr    -84(a6)            ;_LVOAttachCxObj(a6)
  178.     
  179. ; CxTranslate() creates a translate CxObject. When a translate CxObject gets
  180. ; a CxMessage, it deletes the original CxMessage and adds a new input event
  181. ; to the input.device's input stream after the Commodities input handler.
  182. ; CxTranslate's argument points to an InputEvent structure from which to create
  183. ; the new input event.  In this example, the pointer is NULL, meaning no new
  184. ; event should be introduced.
  185.  
  186.     move.l    #CX_TRANSLATE,d0
  187.     sub.l    a0,a0            ;NULL
  188.     sub.l    a1,a1
  189.     jsr    -30(a6)            ;_LVOCreateCxObj(a6)    ;CxTranslate
  190.     move.l    d0,d5
  191.     beq    \error
  192.     move.l    d7,a0            ;filter
  193.     move.l    d0,a1            ;translate object
  194.     jsr    -84(a6)            ;_LVOAttachCxObj(a6)
  195.  
  196.     move.l    d7,a0            ;filter, check for errors
  197.     jsr    -66(a6)            ;_LVOCxObjError(a6)
  198.     tst.l    d0
  199.     bne.s    \error
  200.  
  201.     move.l    d7,d0            ;filter
  202. \out:    movem.l    (a7)+,d1-a6
  203.     rts
  204.  
  205. \error:    moveq    #0,d0
  206.     bra.s    \out
  207.  
  208.     ENDC
  209.  
  210. ;------------------------------------------------------------------------------
  211. *
  212. * RemCX        - remove a commodities object plus all object connected to
  213. *          this network.
  214. *
  215. * INPUT        A0    cx object  (f.e: HotKey filter)
  216. *
  217. ;------------------------------------------------------------------------------
  218.     IFD    xxx_RemCX
  219.  
  220. RemCX:    movem.l    d0-a6,-(a7)
  221.     move.l    CxBase(pc),a6
  222.     jsr    -54(a6)            ;_LVODeleteCxObjAll(a6)
  223.     movem.l    (a7)+,d0-a6
  224.     rts
  225.  
  226.     ENDC
  227.  
  228. ;------------------------------------------------------------------------------
  229. *
  230. * EnableCX    - activate commodity object
  231. *
  232. * INPUT        A0    Broker
  233. *
  234. ;------------------------------------------------------------------------------
  235.     IFD    xxx_EnableCX
  236.  
  237. EnableCX:
  238.     movem.l    d0-a6,-(a7)    
  239.     moveq    #1,d0
  240.     move.l    CxBase(pc),a6
  241.     jsr    -42(a6)            ;_LVOActivateCxObj(a6)
  242.     movem.l    (a7)+,d0-a6
  243.     rts
  244.  
  245.     ENDC
  246.  
  247. ;------------------------------------------------------------------------------
  248. *
  249. * DisableCX    - deactivate commodity object
  250. *
  251. * INPUT        A0    Broker
  252. *
  253. ;------------------------------------------------------------------------------
  254.     IFD    xxx_DisableCX
  255.  
  256. DisableCX:
  257.     movem.l    d0-a6,-(a7)    
  258.     moveq    #0,d0
  259.     move.l    CxBase(pc),a6
  260.     jsr    -42(a6)            ;_LVOActivateCxObj(a6)
  261.     movem.l    (a7)+,d0-a6
  262.     rts
  263.  
  264.     ENDC
  265.  
  266. ;------------------------------------------------------------------------------
  267.  
  268. ;------------------
  269.     base    csr_oldbase
  270.  
  271. ;------------------
  272.     opt    rcl
  273.  
  274. ;------------------
  275.     endif
  276.  
  277.  end
  278.  
  279.